/**
 * 
 */
package com.ms.service.module.baccarat;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.ms.service.module.baccarat.bin.BacrBetType;
import com.xpec.c4.game.utility.GameUtility;

/**
 * 勝負結果
 * 
 * @author TW15010
 */
public class BacrGameResult {
	/** log4j object */
	private static final Log log = LogFactory.getLog(BacrGameResult.class);

	/**
	 * 勝方類型 {@link BacrBetType}
	 */
	private byte winnerType;

	/**
	 * 莊對
	 */
	private boolean bankerPair;

	/**
	 * 閒對
	 */
	private boolean playerPair;

	public BacrGameResult() {
	}

	/**
	 * @param winnerType
	 * @param bankerPair
	 * @param playerPair
	 */
	public BacrGameResult(byte winnerType, boolean bankerPair, boolean playerPair) {
		super();
		this.winnerType = winnerType;
		this.bankerPair = bankerPair;
		this.playerPair = playerPair;
	}

	public byte getWinnerType() {
		return winnerType;
	}

	public void setWinnerType(byte winnerType) {
		this.winnerType = winnerType;
	}

	public boolean isBankerPair() {
		return bankerPair;
	}

	public void setBankerPair(boolean bankerPair) {
		this.bankerPair = bankerPair;
	}

	public boolean isPlayerPair() {
		return playerPair;
	}

	public void setPlayerPair(boolean playerPair) {
		this.playerPair = playerPair;
	}

	public String getWinTypeChar() {
		switch (winnerType) {
		case BacrBetType.PLAYER:
			return "P";
		case BacrBetType.BANKER:
			return "B";
		case BacrBetType.TIE:
			return "T";
		default:
			if (log.isErrorEnabled()) {
				GameUtility.logErrorException(log, "invalid winnerType " + winnerType);
			}
			return "";
		}
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();

		// 勝方
		String winTypeChar = getWinTypeChar();
		if (!GameUtility.isHaveString(winTypeChar)) {
			return "";
		}

		sb.append(winTypeChar);
		sb.append("|");

		// 閒對
		sb.append("PP");
		if (playerPair) {
			sb.append("1");
		} else {
			sb.append("0");
		}
		sb.append("|");

		// 莊對
		sb.append("BP");
		if (bankerPair) {
			sb.append("1");
		} else {
			sb.append("0");
		}

		return sb.toString();
	}
}
